﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Library.Domain;
using System.Runtime.Serialization;

namespace Core.Entities
{
    [DataContract]
    public class BaseEntity<TId>
    {
        [IgnoreDataMember]
        public virtual string IdName
        {
            get
            {
                return "ID";
            }
        }

        [IgnoreDataMember]
        public TId IdValue
        {
            get
            {
                object id = this.GetType().GetProperty(IdName).GetValue(this, null);
                return (TId)Convert.ChangeType(id, typeof(TId));
            }
        }

        public BaseEntity()
        {
            BrokenRules = new List<ValidationRule>();
        }

        private List<ValidationRule> _brokenRules;
        public virtual List<ValidationRule> BrokenRules
        {
            get { return _brokenRules; }
            set { _brokenRules = value; }
        }

        public virtual bool Validate()
        {
            return true;
        }
    }
}
